<template>
    <h2>修改</h2>
    <table border="1">
        <tr>
            <td>代金券标题</td>
            <td>
                <input type="text" v-model="info.Vocher_Title">
            </td>
        </tr>
        <tr>
            <td>代金券颜色</td>
            <td>
                <input type="text" v-model="info.Vocher_Color">
            </td>
        </tr>
        <tr>
            <td>代金券库存</td>
            <td>
                <input type="number" v-model="info.Voucher_Num">
            </td>
        </tr>
        <tr>
            <td>每人限领</td>
            <td>
                <input type="number" v-model="info.Voucher_Limited">
            </td>
        </tr>
        <tr>
            <td>代金券开始有效期</td>
            <td>
                <input type="date" v-model="kaitime">
            </td>
        </tr>
        <tr>
            <td>代金券结束有效期</td>
            <td>
                <input type="date" v-model="jietime">
            </td>
        </tr>
        <tr>
            <td>代金券金额</td>
            <td>
                <input type="number" v-model="info.Voucher_Money">
            </td>
        </tr>
        <tr>
            <td>代金券使用须知</td>
            <td>
                <input type="text" v-model="info.Voucher_Precautions">
            </td>
        </tr>
        <tr>
            <td>客服电话</td>
            <td>
                <input type="text" v-model="info.Voucher_Phone">
            </td>
        </tr>
        <tr>
            <td>门店</td>
            <td>
                <select v-model="info.ShopId">
                    <option :value="0">--请选择--</option>
                    <option v-for="item in Shops" :value="item.ShopId">{{ item.ShopName }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td></td>
            <td>
                <input type="button" value="保存" @click="SaveData">
            </td>
        </tr>
        
    </table>
</template>
<script setup lang="ts">
import axios from 'axios';
import { onMounted,ref } from 'vue';
import { useRoute ,useRouter} from 'vue-router';
const route=useRoute();
const router=useRoute();


const kaitime=ref("");
    const jietime=ref("");
onMounted(()=>{
    GetShop();
    GetVoucher();
})


const GetVoucher=()=>{
    axios.get('https://localhost:7153/api/Voucher/GetVoucher',
    
    {
        params:{
            Voucher_Id:route.params.id
        }
    }
    
    )

    .then(res=>{
        info.value=res.data
        kaitime.value=info.value.Voucher_SDate.substring(0,10)
        jietime.value=info.value.Voucher_EDate.substring(0,10)
    })


}


const Shops=ref([{
    ShopId:0,
    ShopName:""

}])

const GetShop=()=>{

axios.get('https://localhost:7153/api/Voucher/GetShops')
.then(res=>{
    Shops.value=res.data
})


}

const info=ref({
    Vocher_Title:"",
    Vocher_Color:"",
    Voucher_Num:"",
    Voucher_Limited:"",
    Voucher_Money:"",
    Voucher_SDate:"",
    Voucher_EDate:"",
    Voucher_Precautions:"",
    Voucher_Phone:"",
    ShopId:0

})


const SaveData=()=>{

axios.put('https://localhost:7153/api/Voucher/UpdateVoucher',info.value)
.then(res=>{
     if(res.data>0){
        alert("修改成功");
    }
    else{
        alert("修改失败");
    }
})


}

</script>